package rdd;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.broadcast.Broadcast;

import java.util.Arrays;
import java.util.List;

public class Saprk99 {
    public static void main(String[] args) {
        final SparkConf conf = new SparkConf();
        conf.setMaster("local[*]");
        conf.setAppName("spark");
        final JavaSparkContext jsc = new JavaSparkContext(conf);

        final JavaRDD<String> rdd = jsc.parallelize(
                Arrays.asList("Hello","Spark","Hadoop","Flink","Spark","Hadoop")
        );

        //这个集合是在Driver端，保存于Driver端
        final List<String> okList = Arrays.asList("Spark","Hadoop");
        final Broadcast<List<String>> broadcast = jsc.broadcast(okList);            //这里就相当于是把Driver端的数据拉取到了Executor端的缓存中
        JavaRDD<String> filterRDD = rdd.filter(s -> broadcast.value().contains(s));
        filterRDD.collect().forEach(System.out::println);
        jsc.close();
    }
}
